﻿using Architecture.API.Application.Command.RoleCommand;
using Architecture.Domain;
using Architecture.Domain.Service.RoleServices;
using MediatR;
using Microsoft.AspNetCore.Identity;

namespace Architecture.API.Application.CommandHandlers.RoleHandler
{
    public class RoleUpdateCommandHandler : IRequestHandler<RoleUpdateCommand, int>
    {
        /// <summary>
        /// 角色服务
        /// </summary>
        private readonly IRoleService _roleService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleService"></param>
        public RoleUpdateCommandHandler(IRoleService roleService)
        {
            _roleService = roleService;
        }

        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(RoleUpdateCommand request, CancellationToken cancellationToken)
        {
            return await _roleService.UpdateRole(new Role() { RoleName = request.RoleName,RoleId = request.RoleId,UpdatedDate=DateTime.Now });
        }
    }
}
